package service;

import com.wondersgroup.hs.mobile.nursing.rpc.dto.request.QuerySignReq;
import com.wondersgroup.hs.mobile.nursing.rpc.dto.response.SignRsp;
import com.wondersgroup.hs.mobile.nursing.rpc.service.ORMService;

import java.util.List;

/**
 * Created by zarra on 2017/5/17.
 */
public class SignQuery extends RestServiceFunction {

    ORMService ormService ;

    public SignQuery(){
        ormService = restService(ORMService.class);
    }

    @Override
    public Object run(Object[] objects) {
        String patientID = (String) objects[0];
        Integer signID    = (Integer) objects[1];

        Integer index = 0;

        if (objects.length > 2)
            index   = (Integer) objects[2];

        QuerySignReq req = new QuerySignReq();

        req.getPatientIDs().add(patientID);
        req.getSignTypes().add(signID);

        List<SignRsp> signRsps =  ormService.querySign(req);

        SignRsp signRsp = signRsps.get(index);

        String value = signRsp.getValue();

        if (signRsp.getValueEx()!= null){
            value = "/" + signRsp.getValueEx();
        }

        if (signRsp.getValueEx2()!= null){
            value = "/" + signRsp.getValueEx2();
        }

        return value;
    }
}
